package com.wiscamp.ninechapters.problems.adapter.items;

import com.wiscamp.ninechapters.ddd.PersistenceObject;
import lombok.Data;

import java.util.ArrayList;
import java.util.Collection;

/**
 * 问题
 */
@Data
public class QuestionDto implements PersistenceObject {


    /**
     * 问题编号
     */
    private long questionId = 0;

    /**
     * 题编号
     */
    private long itemId = 0;

    /**
     * 题型编号
     */
    private long itemTypeId = 0;

    /**
     * 问题类型编号
     */
    private long questionTypeId = 0;

    /**
     * 问题超文本内容
     */
    private String questionHypertext = "";

    /**
     * 问题翻译
     */
    private String questionTranslation = "";

    /**
     * 答题时间限制
     */
    private int timeLimit = 0;

    /**
     * 问题分数
     */
    private int questionScore = 0;

    /**
     * 高亮文本
     */
    private String highlightText = "";

    /**
     * 难度
     */
    private int difficulty = 0;

    /**
     * 问题序号
     */
    private int questionIndex = 0;

    /**
     * 是否需要解题步骤
     */
    private boolean needSteps = false;

    /**
     * 问题选项列表
     */
    private Collection<QuestionOptionDto> options = new ArrayList<>();

    /**
     * 问题答案列表
     */
    private Collection<QuestionAnswerDto> answers = new ArrayList<>();

    /**
     * 问题解析
     */
    private QuestionAnalysisDto preferredSolution;

    private QuestionAnalysisDto analysis;

    /**
     * 解析列表
     */
    private Collection<QuestionAnalysisDto> solutions = new ArrayList<>();

    /**
     * 操作：CREATE / UPDATE / DELETE
     */
    private String action = "NONE";

    /**
     * 获取答案列表中的第一个答案
     *
     * @return QuestionAnswer
     */
    public QuestionAnswerDto getFirstAnswer() {
        if (answers != null && !answers.isEmpty()) {
            return (QuestionAnswerDto) answers.toArray()[0];
        }
        return null;
    }
}